Socket
Socket
Sign inDemoInstall

phin

Package Overview
Dependencies
0
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    phin

Ultra-simple, lightweight, dependency-free Node.JS HTTP request client


Version published
Weekly downloads
1.2M
increased by1.65%
Maintainers
1
Install size
8.64 kB
Created
Weekly downloads
 

Package description

What is phin?

The phin npm package is a lightweight HTTP client designed for simplicity and minimalism. It is used for making HTTP requests from Node.js environments. It supports promises and can handle various types of requests such as GET, POST, and more.

What are phin's main functionalities?

Simple HTTP GET requests

This code sample demonstrates how to perform a simple HTTP GET request to a specified URL using phin.

const phin = require('phin')

phin('https://example.com', (err, res) => {
  if (err) throw err
  console.log(res.body)
})

HTTP POST requests with JSON

This code sample shows how to perform an HTTP POST request with JSON data using phin.

const phin = require('phin')

const options = {
  url: 'https://example.com/post',
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  data: { key: 'value' }
}

phin(options, (err, res) => {
  if (err) throw err
  console.log(res.body)
})

Promisified HTTP requests

This code sample illustrates how to use phin with promises to make asynchronous HTTP requests.

const phin = require('phin').promisified

async function makeRequest() {
  try {
    const res = await phin('https://example.com')
    console.log(res.body)
  } catch (err) {
    console.error(err)
  }
}

makeRequest()

Other packages similar to phin

Readme

Source

phin logo


The ultra-lightweight Node.js HTTP client

Full documentation | GitHub | NPM

Simple Usage

const p = require('phin')

p('https://ethanent.me', (err, res) => {
	if (!err) console.log(res.body)
})

Install

npm install phin

Why phin?

phin is trusted by some really important projects. The hundreds of contributors at Less, for example, depend on phin as part of their development process.

Also, phin is super lightweight. Like 99.8% smaller than request lightweight. To compare to other libraries, see phin vs. the Competition.

phin became 33% lighter with release 2.7.0!

Quick Demos

Simple POST:

p({
	url: 'https://ethanent.me',
	method: 'POST',
	data: {
		hey: 'hi'
	}
})

Promisified:

const p = require('phin').promisified
;(async () => {
	const res = await p({
		url: 'https://ethanent.me'
	})

	console.log(res.body)
})()

Simple parsing of JSON:

// (In async function in this case.)

const res = await p({
	url: 'https://ethanent.me/name',
	parse: 'json'
})

console.log(res.body.first)

Documentation

See the phin documentation.

phin has util.promisify support. The promisified library can also be accessed with require('phin').promisified!

phin vs. the Competition

Request is over 6MB in size. phin is just 25KB in size.

phin is super lightweight, and it's getting lighter all the time.

It contains all of the common HTTP client features included in competing libraries!

PackageSize (KB)Dependencies
(Tree Count)
Size Comparison
(vs. phin)
request4,44653444.6x
superagent1,23524123.5x
got6644466.4x
snekfetch107010.7x
phin1001x

Keywords

FAQs

Last updated on 22 Oct 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc